package com.ldc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldc.model.SysMenu;
import com.ldc.service.mapper.MenuMapper;
import com.ldc.service.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能说明
 *
 * @auther liudc
 * @since 2023/7/14
 */
@Service
public class MenuImpl extends ServiceImpl<MenuMapper, SysMenu> implements MenuService {

    @Override
    public SysMenu findBy(LambdaQueryWrapper<SysMenu> queryWrapper) {
        return getBaseMapper().selectOne(queryWrapper);
    }

    @Override
    public List<SysMenu> findListBy(LambdaQueryWrapper<SysMenu> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public List<SysMenu> findListByMenuId(List<Long> menuIds) {
        return findListBy(new QueryWrapper<SysMenu>().lambda().in(SysMenu::getId, menuIds));
    }


    @Override
    public SysMenu findByMenuId(long menuId) {
        return findBy(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getId, menuId));
    }

    @Override
    public int batchDeleteBy(LambdaQueryWrapper<SysMenu> queryWrapper) {
        return getBaseMapper().delete(queryWrapper);
    }

    @Override
    public boolean batchAdd(List<SysMenu> sysMenus) {
        return saveBatch(sysMenus);
    }

    @Override
    public int batchDeleteByMenuIds(List<Long> ids) {
        return batchDeleteBy(new LambdaQueryWrapper<SysMenu>()
                .in(SysMenu::getId, ids));
    }
}
